<?php
class Debug implements ArrayAccess{
	private static $_tracks;

	public function __construct(){

	}


	public function addTrack($message){

	}

	public function offsetExists($offset){
		return isset(self::$_tracks[$offset]);
	}

	public function offsetGet($offset){
		if(isset(self::$_track[$offset])){
			return self::$_track[$offset];
		}else{
			throw new Dexception("offset is not exist! Error:({__LINE__} in {__FILE__})");
		}
	}

	public function offsetSet($offset,$value){
		if(is_null(self::$_tracks[$offset])){
			self::$_tracks[] = array(microtime(true),$value);
		}else{
			self::$_tracks[$offset] =  array(number_format((microtime(true)-APP_START_TIME),5),$value);
		}
	}

	public function offsetUnset($offset){
		if(is_null(self::$_tracks[$offset])){
			throw new Dexception("offset is not exist! Error:({__LINE__}) in {__FILE__}");
		}else{
			unset(self::$_tracks[$offset]);
		}
	}

	public static function getTracks(){
		return self::$_tracks;
	}

	public static function buildTrackInfo(){
		$tracks = self::$_tracks;
		if(count($tracks)==0) echo null;
		$html = "<table style='padding:5px;line-height:20px;margin:30px;color:#000000' width='80%' border='1' cellpadding='0' cellspacing='0'><tr><th style='width:100px;'>Time</th><th>Message</th></tr>";
		foreach($tracks as $track){
			$time = $track[0]*1000;
			$html .="<tr><td align='center'>{$time}ms</td><td>&nbsp;&nbsp;{$track[1]}</td></tr>";
		}
		$html .= "</table>";
		echo $html;
	}

	public static function record($message){
		self::$_tracks[] =  array(number_format((microtime(true)-APP_START_TIME),5),$message);
	}

}